﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml.Linq;
using System.IO;
using System.ServiceModel;
using System.ServiceModel.Web;

using Microsoft.Rtc.Collaboration.Samples.HTMLPresenceControls.Service.Common;
using Microsoft.Rtc.Collaboration.Samples.HTMLPresenceControls.Service.PresenceQueryService;
using System.Configuration;

namespace Microsoft.Rtc.Collaboration.Samples.HTMLPresenceControls.Service.PresenceQueryService
{
    [ServiceBehavior(InstanceContextMode = InstanceContextMode.Single)]
    public class Service : IService
    {
        private UcPresenceCache _presenceCache;

        public Service(UcPresenceCache presenceCache)
        {
            _presenceCache = presenceCache;
        }

        public PresenceSubscription GetPresence(string sipUri)
        {
            PresenceSubscription subscription = _presenceCache.GetPresence(sipUri);
            return subscription;
        }

        private bool HandleHttpOptionsRequest()
        {
            if (WebOperationContext.Current.IncomingRequest.Method == "OPTIONS")
            {
                WebOperationContext.Current.OutgoingResponse.Headers.Add("Access-Control-Allow-Origin", "*");
                return true;
            }

            return false;
        }
    }
}
